﻿@model StackExchange.Opserver.Views.PagerDuty.PagerDutyIncidentModel
@{
    Layout = null;
    this.SetPageTitle("PagerDuty Incident Email");
    var i = Model.Incident;
    var acked = i.AcknowledgedBy != null && i.AcknowledgedBy.Any() ? "List" : "Nobody";
    var isSubjectOnly = i.SummaryData?.Count == 1 && i.SummaryData.ContainsKey("subject");
}
<div class="incident-details">
    <h3>Incident Detail: @i.Number</h3>
    <ul>
        @if (isSubjectOnly)
        {
            <li><span class="key">Subject:</span> <span class="value">@i.SummaryData["subject"]</span></li>
        }
        <li><span class="key">Service:</span> <span class="value">@i.AffectedService.Name</span></li>
        <li><span class="key">Link:</span> <span class="value"><a href="@i.Uri" target="_blank">@i.Uri</a></span></li>
        <li><span class="key">Status:</span> <span class="bold @i.MonitorStatus.Class()">@i.Status.GetDescription()</span></li>
        <li><span class="key">Acknowledged By:</span> <span class="value">@acked</span></li>
        @if (i.ResolvedBy != null)
        {
            <li><span class="key">Resolved By:</span> <span class="value">@i.ResolvedBy.FullName</span></li>
        }
        @if (i.LastChangedBy != null)
        {
            <li><span class="key">Last Change:</span> <span class="value">@i.LastChangedBy.FullName - @i.LastChangedOn.ToRelativeTimeSpan()</span></li>
        }
        <li>
            @if (!isSubjectOnly && i.SummaryData != null && i.SummaryData.Any())
            {
                <table>
                    <thead>
                    <tr>
                        <th colspan="2">Summary</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach (var s in i.SummaryData)
                    {
                        <tr>
                            <td class="bold">@s.Key</td>
                            <td>@s.Value</td>
                        </tr>
                    }
                    </tbody>
                </table>
            }
        </li>
    </ul>
    <hr/>
    <table class="striped-dashboard">
        <tbody class="node-header">
        <tr class="category-row">
            <th colspan="8">
                <h3>Incident Log</h3>
            </th>
        </tr>
        <tr>
            <th>Time</th>
            <th>Type</th>
            <th>Message</th>
            <th>Notes</th>
        </tr>
        @foreach (var l in Model.Logs)
        {
            <tr>
                <td>@l.CreationTime.ToRelativeTimeSpan()</td>
                <td>@l.LogType.ToTitleCase()</td>
                <td>@l.Detail.Message</td>
                <td>@l.Note</td>
            </tr>
        }
        </tbody>
    </table>
</div>